﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EShop.Common;
using EShop.BLL;

namespace EShop.Client
{
    public partial class frmEmployeeChangePassword : frmBase
    {
        public frmEmployeeChangePassword()
        {
            InitializeComponent();
        }

        private void frmEmployeeChangePassword_Load(object sender, EventArgs e)
        {
            this.lblEmployeeID.Text = oShopConfigInfo.LoginID;
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string strOldPWD = SystemLibrary.SQLQuoteName(this.txtOld.Text.Trim());
            string strNewPWD = SystemLibrary.SQLQuoteName(this.txtNew.Text.Trim());
            string strRealPWD = SystemLibrary.SQLQuoteName(this.txtReal.Text.Trim());
            if (string.IsNullOrEmpty(strOldPWD))
            {
                MessageBox.Show("请输入原始密码.");
                return;            
            }
            if (string.IsNullOrEmpty(strNewPWD))
            {
                MessageBox.Show("请输入新密码.");
                return; 
            }
            if (string.IsNullOrEmpty(strRealPWD))
            {
                MessageBox.Show("请再次确认密码..");
                return;
            }
            if (strNewPWD.Equals(strRealPWD) == false)
            {
                MessageBox.Show("两次密码输入不一致");
                return; 
            }
            if (strOldPWD.Equals(oShopConfigInfo.LoginPWD) == false)
            {
                MessageBox.Show("原始密码输入不正确.");
                return; 
            }
            if (new EShop.BLL.EmployeeBLL().ChangePassword(oShopConfigInfo.LoginID, strRealPWD))
            {
                MessageBox.Show("密码修改成功.");
                oShopConfigInfo.LoginPWD = strRealPWD;
                //this.DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                MessageBox.Show("密码修改失败.");
                //this.DialogResult = DialogResult.Cancel;
                Close();
            }
        }
    }
}
